var phExt = {
			data:{},
			timer:null,
			log: function(str){
				//alert(str);
			},
			uid: function(){
				return PSLocalStorage.getItem('uid');
			},
			init: function(){
				this.log('init');
				this.getUserKey();
				this.getPublicData();
				this.timer=setInterval("phExt.getData();",1000*60*15);
			},
			getData: function(){
				this.getMy();
				this.getFavorites();
				this.getUserInfo();
			},
			getPublicData: function(){
				this.getTop();
			},
			getUserKey: function(){
				$.get("http://www.photosight.ru/", function(data){
					try
					{
						var rx = /member(\?.*?)\"/gi;
						var rx_m =  rx.exec(data);
						if( rx_m.length>1)
						{	
							var uid =  rx_m[1];
							if (uid)
							{
								phExt.log(uid);
								PSLocalStorage.setItem('uid', uid);
								phExt.getData();
							}
						} else {
							setTimeout("phExt.getUserKey();",1000*10);
						}
					} catch(e){
						setTimeout("phExt.getUserKey();",1000*10);
						this.log(e);
					}
				});
			},
			
			getMy: function(){
				$.ajax({
					url: 'http://www.photosight.ru/notifier/photos' + this.uid(),
					dataType: "text",
					success: function(data){
						phExt.data["xmlMy"] = data;
						PSLocalStorage.setItem('xmlMy', $(data).xml(1));
					}	
				});
			},
			getFavorites: function(){
				$.ajax({
					url: 'http://www.photosight.ru/notifier/favourite_authors_photos' + this.uid(),
					dataType: "text",
					success: function(data){
						phExt.data["xmlFavorites"] = data;
						PSLocalStorage.setItem('xmlFavorites', $(data).xml(1));
					}	
				});
			},
			getUserInfo: function(){
				$.ajax({
					url: 'http://www.photosight.ru/notifier/member' + this.uid(),
					dataType: "xml",
					success: function(data){
						phExt.data["xmlMember"] = data;
						PSLocalStorage.setItem('xmlMember', $(data).xml(1));
					}	
				});			
			}, 
			getTop: function(){
				$.ajax({
					url: 'http://www.photosight.ru/rss/top_50/',
					dataType: "xml",
					success: function(data){
						phExt.data["xmlTop"] = data;
						PSLocalStorage.setItem('xmlTop', $(data).xml(1));
					}	
				});
			},
			redirect: function(url){
					var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                       .getInterface(Components.interfaces.nsIWebNavigation)
                       .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                       .rootTreeItem
                       .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                       .getInterface(Components.interfaces.nsIDOMWindow);
					   
					if(mainWindow && mainWindow.gBrowser){
						var tab = mainWindow.gBrowser.addTab(url);
						mainWindow.gBrowser.selectedTab = tab;
					}
			}
}

